package org.zcl.elastic.service.impl;

import com.fasterxml.jackson.databind.node.ObjectNode;
import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.zcl.elastic.dao.AppEsRepository;
import org.zcl.elastic.dao.UserRepository;
import org.zcl.elastic.entity.Scroll;
import org.zcl.elastic.entity.ScrollDeepRequest;
import org.zcl.elastic.entity.ScrollRequest;
import org.zcl.elastic.entity.User;
import org.zcl.elastic.service.UserService;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * .
 *
 * @author zhuchenglin
 * @since 2024/9/8 21:36
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private AppEsRepository appEsRepository;

    @Autowired
    private UserRepository userRepository;

    @Override
    public Scroll<ObjectNode> findScroll(ScrollRequest request) {
        return appEsRepository.findScroll(request);
    }

    @Override
    public Scroll<ObjectNode> continueScroll(String scrollId) {
        return appEsRepository.findScroll(scrollId);
    }

    @Override
    public List<User> findDeepSearch(ScrollDeepRequest request, Class objectClass) {
        return appEsRepository.findDeepSearch(request, objectClass);
    }

    @Override
    public User save(User user) {
        return userRepository.save(user);
    }

    @Override
    public void deleteById(String id) {
        userRepository.deleteById(id);
    }

    @Override
    public Iterable<User> findAll() {
        return userRepository.findAll();
    }

    @Override
    public Optional<User> findById(String id) {
        return userRepository.findById(id);
    }

    @Override
    public long count() {
        return userRepository.count();
    }

    @Override
    public Boolean existsById(String id) {
        return userRepository.existsById();
    }

    @Override
    public Iterable<User> findAllById(ArrayList<String> ids) {
        return userRepository.findAllById(ids);
    }

    @Override
    public List<User> findByAddressLikeIgnoreCaseOrderByAgeDesc(String address) {
        return userRepository.findByAddressLikeIgnoreCaseOrderByAgeDesc(address);
    }

    @Override
    public Page<User> findByUserNameContaining(String userName, PageRequest page) {
        return userRepository.findByUserNameContaining(userName, page);
    }

    @Override
    public User findByAge(int age) {
        return userRepository.findByAge(age);
    }

    @Override
    public List<User> findByGender(String gender) {
        return userRepository.findByGender(gender);
    }

    @Override
    public Iterable<User> search(QueryBuilder queryBuilder) {
        return userRepository.search(queryBuilder);
    }
}
